<template>
  <el-dialog v-model="dialogShow5" width="30%">
    <div class="titleShow">
      <div class="titles">{{ $t('licence.sys_commandActive') }}</div>
    </div>
    <el-radio style="display: block; margin-bottom: 20px" v-model="switchO" label="1">{{
      $t('licence.sys_kaiqi') }}</el-radio>
    <el-radio style="display: block; margin-bottom: 20px" v-model="switchO" label="2">{{
      $t('licence.sys_guanbi') }}</el-radio>
    <el-form :inline="true" :model="formInline" :rules="rules" ref="formInlines" class="demo-form-inline"
      v-show="switchO == 1">
      <el-form-item :label="$t('licence.sys_zhiling')" prop="num_3">
        <el-input style="width: 300px" v-model="formInline.num_3"
          :placeholder="$t('licence.sys_shuzhi0')"></el-input>
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogShow5 = false">{{ $t('licence.cancel') }}</el-button>
        <el-button type="primary" @click="instruction">{{ $t('licence.determine') }}</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script setup lang="ts">
import { commandControl } from "@/api/inveter/inveter";
import { useI18n } from 'vue-i18n'
const { t } = useI18n()
const dialogShow5 = ref(false) //指令有功调节
const switchO = ref<number | string>(1) //指令有功调节控制
const props = defineProps(['ids','lang','powerStation']);
const formInlines = ref<ElFormInstance>();
const formInline = ref({
  num_3: '' as any,
})
const rules = reactive({
  num_3: [
    {
      required: true,
      message: t("licence.sys_shurushuzhi"),
      trigger: "blur",
    },
  ],
});
const instruction = async ()=>{
  if (switchO.value == 1) {
      await formInlines.value?.validate();
      if (formInline.value.num_3 > 0) {
        ElMessageBox.confirm(t("licence.Submit"), t("licence.Tips"), {
          confirmButtonText: t("licence.determine"),
          cancelButtonText: t("licence.cancel"),
          type: "warning",
        })
          .then(async () => {
            let data = {
              commandId: 5,
              ids: props.ids.join(","),
              setVal: formInline.value.num_3,
              type: switchO.value,
              lang: props.lang,
            };
            await commandControl(data);
            ElMessage({
              type: "success",
              message: t("licence.success"),
            });
          })
          .catch(() => {
            ElMessage({
              type: "info",
              message: t("licence.cancels"),
            });
          });
        dialogShow5.value = false;
      } else {
        ElMessage({
          type: "error",
          message: t("licence.sys_shuzhi0"),
        });
      }
    } else {
      ElMessageBox.confirm(t("licence.Submit"), t("licence.Tips"), {
        confirmButtonText: t("licence.determine"),
        cancelButtonText: t("licence.cancel"),
        type: "warning",
      })
        .then(async () => {
          let data = {
            commandId: 5,
            ids: props.ids.join(","),
            type: switchO.value,
            lang: props.lang,
          };
          await commandControl(data);
          ElMessage({
            type: "success",
            message: t("licence.success"),
          });
        })
        .catch(() => {
          ElMessage({
            type: "info",
            message: t("licence.cancels"),
          });
        });
      dialogShow5.value = false;
    }
}
const openDialog = ()=>{
  dialogShow5.value = true;
  formInline.value.num_3 = "";
  switchO.value = "1"; //指令有功调节控制
}
defineExpose({
  openDialog
})
</script>